/**
 * @summary 频道模块
 */

import * as searchApi from '@/api/search';

export default {
  // 我是模块
  namespaced: true,
  state: {
    // 频道列表
    suggestionList: [],
    // 搜索结果
    searchResult: [],
  },
  mutations: {
    SET_SUGGESTION_LIST(state, newValue) {
      state.suggestionList = newValue;
    },
    SET_SEARCH_RESULT(state, newValue) {
      state.searchResult = newValue;
    },
  },
  actions: {
    async updateSuggestionList(context, searchValue) {
      const res = await searchApi.getSuggestionList(searchValue);
      context.commit('SET_SUGGESTION_LIST', res);
    },
    async updateSearchResult(context, searchValue) {
      const res = await searchApi.getSearchResult(searchValue);
      context.commit('SET_SEARCH_RESULT', res);
    },
  },
};
